package org.example.traing.persistence;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.traing.entity.ChatMessage;

import java.util.List;

@Mapper  // 标明这是一个MyBatis Mapper接口
public interface ChatMessageMapper {

    @Insert("INSERT INTO chat_message (room_id, sender_id, message) VALUES (#{roomId}, #{senderId}, #{message})")
    void insertMessage(ChatMessage message);

    @Select("SELECT * FROM chat_message WHERE room_id = #{roomId}")
    List<ChatMessage> findMessagesByRoomId(String roomId);
}